<template>
    <div id="wai">
        <div id="nei">
            <h1 class="title">{{ msg }}</h1><br />
            <label>省份：<input v-model="address.province" type="text" placeholder="输入省份"></label><br>
            <label>详细地址：<input v-model="address.detailed_address" type="text" placeholder="收件地址"></label><br>
            <label>电话号码：<input v-model="address.phone_number" type="text" placeholder="电话号码"></label><br>
            <button class="but" @click="refer_to">提交</button>
            <button class="but" @click="reset">重置</button>
        </div>
    </div>
</template>
                  
<script>


export default {
    data() {
        return {
            msg: "增加地址",
            address: {
                province: '',
                detailed_address: '',
                phone_number: '',
                session_id: this.$auth.getAuthorization()
            }

        }
    },
    methods: {
        refer_to() {
            console.log('提交');
            this.$http.post('add_address.php', this.address,
                {
                    headers: {
                        'Content-Type': 'application/json' // 设置请求头
                    }
                }
            ).then(response => {
                if (response.data.status === 1) {
                    // alert('成功');
                    console.log('成功');
                    console.log(response);
                    this.$router.push('/user/shipping_address');
                } else {
                    // alert('失败');
                    console.log('失败');
                    alert('参数错误');
                }

            }).catch(error => {
                console.error(error);
            });
            
        },
        reset() {
            console.log('重置');
            this.address = {
                province: '',
                detailed_address: '',
                phone_number: ''
            }
        }
    },
    created() {

    }
}
</script>
  
  <!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
* {
    padding: 0;
    margin: 0;
}

#nei {
    padding-top: 1%;
    font-size: 20px;

    .but {
        width: 150px;
        height: 50px;
        margin-left: 20%;

    }
}
</style>
                                                                          